<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 引入vue + axios + common.js -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <script src="js/common.js"></script>
</head>
<body>
<div id="myApp">
</div>
<script type="text/javascript">
    new Vue({
        el:"#myApp",
        data:{},
        mounted(){
            //http://bugtracker.itsource.cn/callback.html?code=031QtAll2kBeA64RzJol2gpcaW3QtAlk&state=1
            let url = location.href;
            let code = parseUrlParams2Obj(url).code;
            this.$http.get("/login/wechat/"+code).then(res=>{
                if (res.data.success){
                    alert("成功")
                    //2.将token和logininfo保存到localStrorage中
                    let {token,logininfo}  = res.data.resultObj;  //解构表达式：快捷获取
                    // console.log("===============================================");
                    // console.log(res.data.resultObj);
                    localStorage.setItem("token",token);
                    //注意：保存的是json格式的字符串，那么获取的时候需要进行转换才能使用json对象
                    localStorage.setItem("logininfo",JSON.stringify(logininfo));//拿到的是一个对象，需要转成json格式字符串
                    location.href="index.html";
                } else {
                    var openid = res.data.resultObj.openid;
                    var access_token = res.data.resultObj.access_token;
                    location.href = "binder.html?openid="+openid+"&access_token="+access_token;
                }
            }).catch(res=>{
                alert("again")
            });
        }
    });
</script>
</body>
</html>